package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.controller.es.EsUnService;
import com.ruoyi.system.controller.es.dto.EsSearch;
import com.ruoyi.system.domain.vo.web.WebPeopleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FyPeopleMapper;
import com.ruoyi.system.domain.FyPeople;
import com.ruoyi.system.service.IFyPeopleService;

/**
 * 传承人信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Service
public class FyPeopleServiceImpl implements IFyPeopleService
{
    @Autowired
    private FyPeopleMapper fyPeopleMapper;
    @Autowired
    private EsUnService esUnService;
    /**
     * 查询传承人信息
     *
     * @param peopleId 传承人信息主键
     * @return 传承人信息
     */
    @Override
    public FyPeople selectFyPeopleByPeopleId(Long peopleId)
    {
        return fyPeopleMapper.selectFyPeopleByPeopleId(peopleId);
    }

    /**
     * 查询传承人信息列表
     *
     * @param fyPeople 传承人信息
     * @return 传承人信息
     */
    @Override
    public List<FyPeople> selectFyPeopleList(FyPeople fyPeople)
    {

        return fyPeopleMapper.selectFyPeopleList(fyPeople);
    }

    @Override
    public List<WebPeopleVo> selectWebPeople(String peopleName, String projectName, String projectType, String peopleLevel) {
        return fyPeopleMapper.selectWebPeople( peopleName,  projectName,  projectType,  peopleLevel);
    }

    /**
     * 新增传承人信息
     *
     * @param fyPeople 传承人信息
     * @return 结果
     */
    @Override
    public int insertFyPeople(FyPeople fyPeople)
    {
        fyPeople.setIsDelete(0l);
        fyPeople.setCreateTime(DateUtils.getNowDate());
        return fyPeopleMapper.insertFyPeople(fyPeople);
    }

    /**
     * 修改传承人信息
     *
     * @param fyPeople 传承人信息
     * @return 结果
     */
    @Override
    public int updateFyPeople(FyPeople fyPeople)
    {
        fyPeople.setUpdateTime(DateUtils.getNowDate());
        return fyPeopleMapper.updateFyPeople(fyPeople);
    }

    /**
     * 批量删除传承人信息
     *
     * @param peopleIds 需要删除的传承人信息主键
     * @return 结果
     */
    @Override
    public int deleteFyPeopleByPeopleIds(Long[] peopleIds)
    {
        for (Long l:peopleIds){
            FyPeople fyPeople=new FyPeople();
            fyPeople.setPeopleId(l);
            fyPeople.setIsDelete(1l);
            fyPeopleMapper.updateFyPeople(fyPeople);
            EsSearch esSearch=new EsSearch();
            esSearch.setId(fyPeople.getPeopleId());
            esSearch.setLanmu("资源-非遗传承人");
            esSearch.setLanmuId(2);
            esUnService.delete(esSearch);
        }

        return 1;
    }

    /**
     * 删除传承人信息信息
     *
     * @param peopleId 传承人信息主键
     * @return 结果
     */
    @Override
    public int deleteFyPeopleByPeopleId(Long peopleId)
    {
        return fyPeopleMapper.deleteFyPeopleByPeopleId(peopleId);
    }
}
